﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Noria.Web.MyMSDN;
using Noria.Web.Utility;

namespace Noria.Web.Test
{
    [TestClass]
    public class RestoreTest
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        [TestMethod]
        public void RestoreDatabase()
        {
            HttpBot.RequestNonQuery(null,
                (string)NConfig.Root.spider.settings.mymsdn + "/restore.ashx?z=20131015055318060_new.gz", new byte[] { 0 }, null,
                new Dictionary<string, string> { { "NAuth", CreateIdentityToken() } });
            log.Info("Restore database successfully.");
        }

        private static string CreateIdentityToken()
        {
            string user = NConfig.Root.identity.user;
            string code = NConfig.Root.identity.code;
            var buffer = Encoding.UTF8.GetBytes(user + ":" + code);
            var passcode = "Noria " + Convert.ToBase64String(buffer);
            return passcode;
        }
    }
}
